<template>
  <div>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column label="教室编号" width="180">
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span style="margin-left: 10px">{{ scope.row.room_id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="教室名称" width="180">
        <template slot-scope="scope">
          <el-popover trigger="hover" placement="top">
            <p>姓名: {{ scope.row.room_text }}</p>
            <p>住址: {{ scope.row.room_id }}</p>
            <div slot="reference" class="name-wrapper">
              <el-tag size="medium">{{ scope.row.room_text }}</el-tag>
            </div>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button
          >
          <el-dialog
            title="修改信息"
            :visible.sync="openOff"
            center
            :append-to-body="true"
            :lock-scroll="false"
            width="60%"
          >
            <Tiger> </Tiger>
          </el-dialog>
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import Tiger from "./ui/tiger.vue";
import { getTiger, delTiger } from "../../../api/tiger";
export default {
  data() {
    return {
      tableData: [],
      openOff: false,
    };
  },
  methods: {
    handleEdit(index, row) {
      this.openOff = true; //默认页面不显示为false,点击按钮将这个属性变成true
    },
    handleDelete(index, row) {
      delTiger({
        room_id: row.room_id,
      }).then((res) => {
          if(res.data.msg === '删除成功'){
               this.tableData.splice(index, 1);
                this.$message({
                message: "删除教室成功",
                type: "success",
              });
          }else{
              this.$message({
                message: "删除教室失败",
                type: "error",
              });
          }
      });

     
    },
  },
  components: {
    Tiger,
  },
  mounted() {
    getTiger().then((res) => {
      this.tableData = res.data.data;
    });
  },
};
</script>

<style>
</style>